using System;

namespace FunctionalProgramming.PatternMatching.TransformingRules
{
   internal class PredicateMatchingConstantOutput<TIn, TOut> : ITransformingRule<TIn, TOut>
   {
      private readonly Predicate<TIn> predicate;
      private readonly TOut constantOutput;

      public PredicateMatchingConstantOutput(Predicate<TIn> predicate, TOut constantOutput)
      {
         this.predicate = predicate;
         this.constantOutput = constantOutput;
      }

      public bool DoesInputMatch(TIn input)
      {
         bool result = predicate(input);
         return result;
      }

      public TOut TransformInput(TIn input)
      {
         return constantOutput;
      }
   }
}